import { defineStore } from "pinia";
import {
  type pqbExerciseType,
  store,
  router,
  resetRouter,
  routerArrays,
  storageLocal
} from "../utils";
import {
  type PqbExerciseResult,
  getPqbExercise,
  getPqbAnswer
} from "@/api/pqb";
// import { useMultiTagsStoreHook } from "./multiTags";
// import { type DataInfo, setToken, removeToken, userKey } from "@/utils/auth";

/*

  userId?: number;
  questionId?: number;
  question?: string;
  answer?: string;
  viewTimes?: number;
  errorTimes?: number;
  tags?: Array<string>;
*/
// const pqbExerciseKey = "pqbExerciseKey";
export const usePqbExerciseStore = defineStore("usePqbExerciseStore", {
  state: (): pqbExerciseType => ({}),
  actions: {
    /** 登入 */
    async doGetPqbExercise() {
      return new Promise<PqbExerciseResult>((resolve, reject) => {
        getPqbExercise()
          .then(data => {
            if (data?.success) console.log("ok");
            resolve(data);
          })
          .catch(error => {
            reject(error);
          });
      });
    },
    /** 刷新`token` */
    async doGetPqbAnswer() {
      return new Promise<PqbExerciseResult>((resolve, reject) => {
        getPqbAnswer()
          .then(data => {
            if (data) {
              resolve(data);
            }
          })
          .catch(error => {
            reject(error);
          });
      });
    }
  }
});

export function usePqbStoreHook() {
  return usePqbExerciseStore(store);
}
